
//
//  SYDIFIManage.m
//  PinGJByOwnerSide
//
//  Created by lantaiyuan on 2017/9/8.
//  Copyright © 2017年 lantaiyuan. All rights reserved.
//

#import "SYDIFIManage.h"

@implementation SYDIFIManage
//语音字符串
- (void)openIFlySpeechWithSpeaking:(NSString *)speaking{

    [self initIfy];
    //启动合成会话
    [_iFlySpeechSynthesizer startSpeaking:speaking];
}

//外部调用控制关闭ifi
- (void)closeIFlySpeech{

    _iFlySpeechSynthesizer.delegate = nil;
    _iFlySpeechSynthesizer  = nil;
}

-(void)initIfy{
    //通过appid连接讯飞语音服务器，把@"53b5560a"换成你申请的appid
    
    NSString *initString = [[NSString alloc]initWithFormat:@"appid=%@,timeout=%@",@"59a5138d",@"10"];
    
    //所有服务启动前，需要确保执行createUtility
    [IFlySpeechUtility createUtility:initString];
    
    //创建合成对象，为单例模式
    _iFlySpeechSynthesizer = [IFlySpeechSynthesizer sharedInstance];
    _iFlySpeechSynthesizer.delegate = self;
    
    //设置语音合成的参数
    //合成的语速,取值范围0~100
    
    [_iFlySpeechSynthesizer setParameter:@"50" forKey:[IFlySpeechConstant SPEED]];
    
    //合成的音量;取值范围0~100
    
    [_iFlySpeechSynthesizer setParameter:@"50" forKey:[IFlySpeechConstant VOLUME]];
    
    //发音人,默认为”xiaoyan”;可以设置的参数列表可参考个性化发音人列表
    [_iFlySpeechSynthesizer setParameter:@"xiaoyan"
     
                                  forKey:[IFlySpeechConstant VOICE_NAME]];
    
    //音频采样率,目前支持的采样率有16000 和 8000
    [_iFlySpeechSynthesizer setParameter:@"8000"
     
                                  forKey:[IFlySpeechConstant SAMPLE_RATE]];
    
    ////asr_audio_path保存录音文件路径，如不再需要，设置value为nil表示取消，默认目录是documents
    
    [_iFlySpeechSynthesizer setParameter:@"tts.pcm" forKey:[IFlySpeechConstant TTS_AUDIO_PATH]];
}

#pragma mark---IFlySpeechSynthesizerDelegate
//开始播放
-(void)onSpeakBegin{
    NSLog(@"开始播放语音");
}
//缓冲进度
-(void)onBufferProgress:(int)progress message:(NSString *)msg
{
    
}

//播放进度
-(void)onSpeakProgress:(int)progress{
    
}

//暂停播放
-(void)onSpeakPaused{
    
}
//恢复播放
-(void)onSpeakResumed{
    
}
//结束回调
-(void)onCompleted:(IFlySpeechError *) error{
    NSLog(@"----error:%@",error);
}
@end
